use std::path::Path;

// Module declarations
pub mod commands;

// Re-export the main types and functions
pub use crate::commands::storage::AppDb;

// File hiding utilities
#[cfg(target_os = "windows")]
pub fn hide_file_windows(path: &Path) -> std::io::Result<()> {
    use std::os::windows::ffi::OsStrExt;
    use windows::Win32::Storage::FileSystem::{SetFileAttributesW, FILE_ATTRIBUTE_HIDDEN};
    
    let wide_path: Vec<u16> = path.as_os_str()
        .encode_wide()
        .chain(std::iter::once(0))
        .collect();
    
    unsafe {
        SetFileAttributesW(
            windows::core::PCWSTR(wide_path.as_ptr()),
            FILE_ATTRIBUTE_HIDDEN,
        ).map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, format!("{:?}", e)))?;
    }
    
    log::info!("File hidden successfully: {:?}", path);
    Ok(())
}

#[cfg(target_os = "windows")]
pub fn unhide_file_windows(path: &Path) -> std::io::Result<()> {
    use std::os::windows::ffi::OsStrExt;
    use windows::Win32::Storage::FileSystem::{SetFileAttributesW, FILE_ATTRIBUTE_NORMAL};
    
    let wide_path: Vec<u16> = path.as_os_str()
        .encode_wide()
        .chain(std::iter::once(0))
        .collect();
    
    unsafe {
        SetFileAttributesW(
            windows::core::PCWSTR(wide_path.as_ptr()),
            FILE_ATTRIBUTE_NORMAL,
        ).map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, format!("{:?}", e)))?;
    }
    
    log::info!("File unhidden successfully: {:?}", path);
    Ok(())
}

#[cfg(not(target_os = "windows"))]
pub fn hide_file_windows(_path: &Path) -> std::io::Result<()> {
    // On non-Windows platforms, do nothing
    Ok(())
}

#[cfg(not(target_os = "windows"))]
pub fn unhide_file_windows(_path: &Path) -> std::io::Result<()> {
    // On non-Windows platforms, do nothing
    Ok(())
}
